package com.biz.primus.management.tms.controller;

import com.biz.primus.management.tms.feign.UpgradeFeignClient;
import com.biz.primus.model.tms.vo.UpgradeAddReqVo;
import com.biz.primus.model.tms.vo.UpgradeDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/upgrade")
//@Secured("ROLE_UPGRADE")
public class UpgradeController {

    @Autowired
    private UpgradeFeignClient upgradeFeignClient;

    @RequestMapping("/list")
//	@PreAuthorize("hasAuthority('OPT_UPGRADE_LIST')")
    public ModelAndView list() {
        ModelAndView view = new ModelAndView("upgrade/list");
        List<UpgradeDetailVo> ios = upgradeFeignClient.findByOs("ios");
        List<UpgradeDetailVo> androId = upgradeFeignClient.findByOs("android");
        view.addObject("ios", ios);
        view.addObject("android", androId);
        return view;
    }

    @RequestMapping("/add")
//    @PreAuthorize("hasAuthority('OPT_UPGRADE_ADD')")
    public ModelAndView add() {
        ModelAndView view = new ModelAndView("upgrade/add");
        view.addObject("cmd", "add");
        return view;
    }


    @RequestMapping("/delete")
//    @PreAuthorize("hasAuthority('OPT_UPGRADE_DELETE')")
    public ModelAndView delete(@RequestParam("id") Long id) {
        upgradeFeignClient.disable(id);
        return new ModelAndView("redirect:/upgrade/list.do");
    }

    @RequestMapping("/save_add")
//    @PreAuthorize("hasAuthority('OPT_UPGRADE_SAVEADD')")
    public ModelAndView save_add(UpgradeAddReqVo upgrade) {
        upgradeFeignClient.save(upgrade);
        return new ModelAndView("redirect:/upgrade/list.do");
    }

}
